//
//  GYDNetWorkTools.swift
//  Weibo
//
//  Created by 贵永冬 on 16/7/25.
//  Copyright © 2016年 贵永冬. All rights reserved.
//

import UIKit
import AFNetworking

class GYDNetWorkTools: NSObject {
    static let shareInstance : GYDNetWorkTools = GYDNetWorkTools()
    private override init() {
        
    }
    private lazy var sessionManager : AFHTTPSessionManager = {
        let session = AFHTTPSessionManager(baseURL:nil)
        session.requestSerializer.timeoutInterval = 10.0
        session.responseSerializer.acceptableContentTypes = NSSet(array: ["text/plain","application/json","text/json","text/javascript"]) as? Set

        return session
    }()
    
    
    
    func httpPostWithUrl(url : String, parames: AnyObject?,successBlock: ((result: AnyObject?) -> ())?, failureBlock: ((error : NSError) -> ())? ) {
        
        sessionManager.POST(url, parameters: parames, progress: { (progress) in
            
            }, success: { (task, responseObject) in
                if let tempSuccessBlock = successBlock {
                    tempSuccessBlock(result: responseObject)
                }
            }) { (task, error) in
                if let tempFailureBlock = failureBlock {
                    tempFailureBlock(error: error)
                }
        }
    }
    
    func httpGetWithUrl(url : String, parames: AnyObject?,successBlock: ((result: AnyObject?) -> ())?, failureBlock: ((error : NSError) -> ())? ) {
        sessionManager.GET(url, parameters: parames, progress: { (progress) in
            
            }, success: { (task, responseObject) in
                if let tempSuccessBlock = successBlock {
                    tempSuccessBlock(result: responseObject)
                }
            }) { (task, error) in
                if let tempFailureBlock = failureBlock {
                    tempFailureBlock(error: error)
                }
        }
    }
    
    
    
}
